const { Sequelize, Model, INTEGER } = require('sequelize')
const { db } = require('../core/sequelize')
class Mall extends Model {
    //static关键字静态方法 不用new 可以直接调用

    static async getList(id) {
        // where查询
        if (id) {
            const list = await Mall.findAll({
                where: {
                    id
                }
            })
            return list
        } else {
            const list = await Mall.findAll()
            return list
        }

    }
}
Mall.init(
    {
        id: {
            type: Sequelize.INTEGER,
            primaryKey: true, //设置主键
            autoIncrement: true,
        },
        url: Sequelize.STRING, //类型 字符串
        name: Sequelize.STRING, //类型 字符串
        integral: Sequelize.INTEGER, //类型 字符串
        stock: Sequelize.INTEGER, //类型 字符串
        // createTime: Sequelize.STRING, //类型 字符串
    },
    {
        // underscored: true,
        sequelize: db,
        modelName: 'mall', timestamps: false
    }
)
module.exports = { Mall }
